// components/myPage/mypage.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    nav:[
      { name:'每日推荐',
        url:'../../icon/tuijian.png'
      },
      {
        name:'歌单',
        url:'../../icon/gedan.png'
      },
      {
        name:'排行榜',
        url:'../../icon/paixingbang.png'
      },
      {
        name:'电台',
        url:'../../icon/music.png'
      },
      {
        name:'直播',
        url:'../../icon/zhibo.png'
      }
    ],
    pageList:[
      {
        name:'本地音乐',
        picurl:'../../icon/mypage/yinyue.png'
      },
      {
        name:'最近播放',
        picurl:'../../icon/mypage/bofang.png'
      },
      {
        name:'下载管理',
        picurl:'../../icon/mypage/xiazai.png'
      },
      {
        name:'我的电台',
        picurl:'../../icon/mypage/yinle.png'
      },
      {
        name:'我的收藏',
        picurl:'../../icon/mypage/shoucang.png'
      }
    ],
    jiantouurlCr:true,
    jiantouurlCo:true,
    createGedan:[],//创建的歌单
    collectGedan:[]//收藏的歌单
  },
  attached(){
    let id = wx.getStorageSync('user').profile.userId;
    console.log(this.getGedan)
    this.getGedan(id)
  },
  /**
   * 组件的方法列表
   */
  methods: {
    changeJiantouCr(e){
      let flag = this.data.jiantouurlCr
      this.setData({
        jiantouurlCr:!flag
      })
    },
    changeJiantouCo(e){
      let flag = this.data.jiantouurlCo
      this.setData({
        jiantouurlCo:!flag
      })
    },
    getGedan(id){
      var reqTask = wx.request({
        url: 'http://musicapi.leanapp.cn/user/playlist',
        data: {uid:id},
        header: {'content-type':'application/json'},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (result) => {
          console.log(result)
          let create=[],collect=[];
          if(result.statusCode==200){
            for(let i in result.data.playlist){
              if(result.data.playlist[i].subscribedCount == 0){
                create.push(result.data.playlist[i])
              }else{
                collect.push(result.data.playlist[i])
              }
            }
            this.setData({
              createGedan:create,
              collectGedan:collect
            })
            console.log(this.data)
            
          }
        },
        fail: (err) => {console.log(err)},
      });
        
    }
    
  }
})
